package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.mapper.UserInfoMapper;
import com.itheima.service.db.UserInfoService;
import com.itheima.vo.PageBeanVo;
import com.itheima.vo.UserInfoVo;
import com.sun.org.apache.bcel.internal.generic.LADD;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author zsk
 * @create 2022-03-14-16:39
 */
@DubboService
public class UserInfoServiceImpl implements UserInfoService {

    //依赖注入
    @Autowired
    private UserInfoMapper userInfoMapper;

    //用户首次登录补全信息
    @Override
    public void loginReginfo(UserInfo userInfo) {
        //调用mapper层保存
        userInfoMapper.insert(userInfo);
    }

    //头像上传
    @Override
    public void update(UserInfo userInfo) {
        //调用mapper
        userInfoMapper.updateById(userInfo);
    }

    //查询用户，根据id
    @Override
    public UserInfo findById(Long id) {
        return userInfoMapper.selectById(id);
    }

    //分页查询用户列表
    @Override
    public PageBeanVo findUserInfoByPage(Integer pageNum, Integer pageSize) {

        //构建查询条件
        Page<UserInfo> page = new Page<>(pageNum, pageSize);
        //查询
        page = userInfoMapper.selectPage(page,null);

        //返回PageBeanVo对象
        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }

}
